from Products.Archetypes.public import StringField, StringWidget
from apkn.resource.interfaces import IResource
from archetypes.schemaextender.field import ExtensionField
from archetypes.schemaextender.interfaces import ISchemaExtender, IBrowserLayerAwareExtender
from interfaces import IVirtualTreeCategoriesSpecific
from zope.component import adapts
from zope.interface import implements

class _ExtensionStringField(ExtensionField, StringField): pass

class ResourceExtender(object):
    adapts(IResource)
    implements(ISchemaExtender, IBrowserLayerAwareExtender)
    
    layer = IVirtualTreeCategoriesSpecific
    
    fields = [
        _ExtensionStringField(
            "resourcecategorypath",
            schemata="categorization",
            searchable=True,
            widget = StringWidget(
                label=u"Category Path",
                description=u"Full category path assigned to this object",
            ),
        ),
    ]

    def __init__(self, context):
        self.context = context

    def getFields(self):
        return self.fields
        
